package com.itcast.discover.service;
import com.itcast.discover.mapper.DiscoverCMapper;
import com.pojo.discover.pojo.DiscoverC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DiscoverCService {
    @Autowired(required = false)
    private DiscoverCMapper discoverCMapper;

    @Autowired(required = false)
    private DiscoverService discoverService;

    /*
    * 查找所有的分类
    * */
    public List<DiscoverC> findDiscoverCAll(){

        List<DiscoverC> discoverCS = discoverCMapper.selectList(null);
        return discoverCS;
    }

    /*
    * 根据id修改的分类信息
    * */
    public void updateDiscoverC(DiscoverC discoverC) {
        discoverCMapper.updateById(discoverC);
    }

    /*
    * 根据id删除分类
    * */
    public Boolean deleteByCid(Integer cid) {
       Boolean isHave= discoverService.findDiscoverBySid(cid);
       if(isHave){
          return false;
       }
       discoverCMapper.deleteById(cid);
       return true;
    }

    /*
    * 新增分类
    * */
    public void insertDiscoverC(DiscoverC discoverC) {

        discoverCMapper.insert(discoverC);
    }
}
